﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Syspetro.Core.GoogleAuth.Google2
{
    public class GoogleAuthenticatorProvider2
    {
        private readonly GoogleAuthOptions options;
        private readonly GoogleAuthenticator2 authenticator;

        public GoogleAuthenticatorProvider2()
        {
            options = new GoogleAuthOptions();
            InternalApp.Configuration.Bind("GoogleAuthOptions", options);
            authenticator = new GoogleAuthenticator2();
        }

        public bool Validate(string Salt, string twofactor_code)
        {
            var code = authenticator.GenerateCode(Salt);
            if (code == twofactor_code)
                return true;
            return false;
        }

        public GoogleAuthenticatorBinding2 Generate(string username)
        {
            return authenticator.Generate(username, options.Issuer);
        }
    }
}
